package com.wisemoresystem.seal.web;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.wisemoresystem.seal.model.t_user;

public class WebTools {

	public static HttpServletRequest getRequest() {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes()).getRequest();
		return request;
	}

	public static HttpSession getSession() {
		HttpSession sn = WebTools.getRequest().getSession();
		return sn;
	}

	// 获取当前登录用户
	public static t_user getCurrentUser() {
		t_user user = (t_user) getSession().getAttribute(SessionVal.login_user);
		return user;
	}

	public static String getCurrentUserId() {
		t_user user = getCurrentUser();
		return user == null ? null : user.get_id();
	}

	public static String getCurrentBankId() {
		t_user user = getCurrentUser();
		return user == null ? null : user.getBank_id();
	}

	public static Set<String> getCurrentRoleCodes() {
		Set<String> roleCodes = (Set<String>) getSession().getAttribute(
				SessionVal.role_codes);
		return roleCodes;
	}

	public static String getCurrentUserUname() {
		t_user user = getCurrentUser();
		return user == null ? null : user.getUname();
	}

}
